From 89f32128f37d99b490de7590e2116a9cfd853f89 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Fri, 22 Dec 2023 17:33:46 +0700
Subject: Update promotion program feature

---
 src-migrate/pages/api/promotion-program/[id].tsx | 43 ++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100644 src-migrate/pages/api/promotion-program/[id].tsx

(limited to 'src-migrate/pages/api/promotion-program/[id].tsx')

diff --git a/src-migrate/pages/api/promotion-program/[id].tsx b/src-migrate/pages/api/promotion-program/[id].tsx
new file mode 100644
index 00000000..ba716e85
--- /dev/null
+++ b/src-migrate/pages/api/promotion-program/[id].tsx
@@ -0,0 +1,43 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { SolrResponse } from "~/common/types/solr";
+import moment from 'moment'
+
+const SOLR_HOST = process.env.SOLR_HOST as string
+
+export default async function handler(req: NextApiRequest, res: NextApiResponse) {
+  const id = req.query.id as string
+
+  if (req.method === 'GET') {
+    const queryParams = new URLSearchParams({ q: `id:${id}` })
+    const response = await fetch(`${SOLR_HOST}/solr/promotion_programs/select?${queryParams.toString()}`)
+    const data: SolrResponse<any[]> = await response.json()
+
+    if (data.response.numFound === 0) {
+      res.status(404).json({ error: 'Program not found' })
+      return
+    }
+
+    const program = await map(data.response.docs[0])
+
+    res.status(200).json({ data: program })
+  }
+}
+
+const map = async (program: any) => {
+  const data: any = {}
+
+  data.id = program.id
+  data.name = program.name_s
+  data.start_time = program.start_time_s
+  data.end_time = program.end_time_s
+  data.applies_to = program.applies_to_s
+  data.time_left = (new Date(data.end_time).getTime() - new Date().getTime()) / 1000
+
+  // const duration = moment.duration(data.time_left, 'seconds')
+  // const days = duration.days()
+  // const hours = duration.hours()
+  // const minutes = duration.minutes()
+  // const seconds = duration.seconds()
+
+  return data
+}
\ No newline at end of file
-- 
cgit v1.2.3


From f62b2345f463695ef0f8f79830cd76b6e0332821 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Sat, 13 Jan 2024 10:35:22 +0700
Subject: Refactor src migrate folder

---
 src-migrate/pages/api/promotion-program/[id].tsx | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

(limited to 'src-migrate/pages/api/promotion-program/[id].tsx')

diff --git a/src-migrate/pages/api/promotion-program/[id].tsx b/src-migrate/pages/api/promotion-program/[id].tsx
index ba716e85..c509b802 100644
--- a/src-migrate/pages/api/promotion-program/[id].tsx
+++ b/src-migrate/pages/api/promotion-program/[id].tsx
@@ -1,6 +1,5 @@
 import { NextApiRequest, NextApiResponse } from "next";
-import { SolrResponse } from "~/common/types/solr";
-import moment from 'moment'
+import { SolrResponse } from "~/types/solr";
 
 const SOLR_HOST = process.env.SOLR_HOST as string
 
-- 
cgit v1.2.3

